<template>
  <view>
    <text>测试阻止返回的页面</text>
    <view class="" v-if="isShow">
      <page-container :show="isShow" :overlay="false" @beforeleave="beforeleave"></page-container>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return { isShow: true, //一开始显示
      }
    },
    methods: {
      beforeleave() {
        this.isShow = false
        uni.showModal({
          title: '确认退出',
          success: e => {
            if (e.confirm) {
              let pages = getCurrentPages()
              if (pages.length === 1) {
                // 返回首页
                uni.switchTab({ url: '/pages/home/home' })
              } else {
                // 返回上一页面
                uni.navigateBack({ delta: 1 })
              }
            } else {
              // 点击取消
              this.isShow = true
            }
          }
        })
      }
    },
    onLoad() {

    }
  }
</script>

<style lang="scss">

</style>